package InheritanceAndPolymorphism.demo07;

public class Hero {
    private String name;
    private Pet pet;

    public Hero(String name) {
        this.name = name;
        this.pet = null;
    }

    public Hero(String name, Pet pet) {
        this.name = name;
        this.pet = pet;
    }

    public void run() {
        System.out.println(name + " 跑，");
        if (pet != null) {
            pet.follow();
        } else {
            System.out.println("他没有宠物跟随");
        }
    }
}
